using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Roslyn.Compilers.Common;
using Roslyn.Compilers.CSharp;
using FernUniHagen.CompilerExtension.Interfaces;
using FernUniHagen.CompilerExtension.DataStructures;

namespace FernUniHagen.CompilerExtension.Adaptor
{
    public class MethodDeclarationAdaptor : DeclarationBase, IDeclaration<CommonSyntaxNode>
    {
        #region member
        public MethodDeclarationSyntax _methodDeclaration;
        #endregion

        #region Constructor


        public MethodDeclarationAdaptor(ISemanticModel model, MethodDeclarationSyntax node) 
        {
            this.SemanticModel = model;
            _methodDeclaration = node;
            Initialize();
        }
        #endregion

        /// <summary>
        /// Returns the name of the variable
        /// </summary>
        /// <returns></returns>
        public override string GetName()
        {
            return _methodDeclaration.Identifier.ToString() ;
        }

        public override TypeSyntax GetTypeSyntax()
        {
            return _methodDeclaration.ReturnType;
        }

        public override SyntaxList<AttributeListSyntax> GetAttributes()
        {
            return _methodDeclaration.AttributeLists;
        }

        public override StatementReplacement<CommonSyntaxNode> ConvertToMutiplicity(string newVariableName)
        {

            //GenericNameSyntax genericType = null;
            //AttributeType attrType = AttributeType.None;
            //GetMultiplicityAttribute(out attrType, out genericType);

            var newIdentifier = Syntax.ParseToken(newVariableName);
            _methodDeclaration = _methodDeclaration.WithIdentifier(newIdentifier);
          
            if (MultiplicityType == AttributeType.Any)
            {
                return new StatementReplacement<CommonSyntaxNode>(_methodDeclaration, _methodDeclaration.WithReturnType(GenericName));
            }
            return new StatementReplacement<CommonSyntaxNode>(_methodDeclaration,_methodDeclaration);
        }
    }
}
